package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.NotEnoughFundsException;

public abstract class AbstractAccount implements Account{

	protected int id;
	protected double balance;

	public AbstractAccount(final double amount) {
		if (amount < 0) {
			throw new IllegalArgumentException();
		}
		this.balance = amount;
	}
	
	@Override
	public double getBalance() {
		return balance;
	}
	
	@Override
	public void deposit(final double amount){
		this.balance = this.balance + amount;
		System.out.println(" succsessful. Your balance now: "+this.balance);
	}
	
	@Override
	public void withdraw(final double amount) throws NotEnoughFundsException{
		if (this.balance < amount) {
			throw new NotEnoughFundsException("Not EnoughFunds"); 
		}
		if (this.balance >= amount) {
			this.balance = this.balance - amount;				
		}
	}
	
	public double maximumAmountToWithdraw(){
		return balance;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof AbstractAccount)) {
			return false;
		}
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance)) {
			return false;
		}
		return true;
	}

	@Override
	public long decimalValue() {
		return Math.round(balance);
	}
	
}
